<template>
  <div class="wrapper">
    等等
<router-link to="/index">去index</router-link>
    <button @click="submitFn('ruleForm')">点击</button>
  </div>
</template>

<script lang="ts">
import {
  defineComponent,
  ref,
  reactive,
  computed,
  watch,
  getCurrentInstance,
  onMounted
} from "vue";
import { useRouter } from "vue-router";
import actions from "@/micro/actions";
export default defineComponent({
  name: "home",
  components: {},
  setup() {
    let state: any = reactive({
      ruleForm: {
        username: "admin",
        password: "admin"
      }
    });
    // 挂载后生命周期
    onMounted(() => {
      console.log(2);
      // 注册一个观察者函数
      actions.onGlobalStateChange((state, prevState) => {
        // state: 变更后的状态; prevState: 变更前的状态
        console.log("主应用观察者：token 改变前的值为 ", prevState.token);
        console.log(
          "主应用观察者：登录状态发生改变，改变后的 token 的值为 ",
          state.token
        );
      }); 
   
    });

    const router = useRouter();
    const submitFn = () => {
      console.log(1);

      actions.setGlobalState({ token:122 });
    };

    return {
      ...state,
      submitFn
    };
  }
});
</script>

<style scoped>
.app_content {
  background: #fff;
  padding: 20px;
  position: relative;
  padding-bottom: 30px;
}
</style>
